<?php
/*$str='w o z h e n d e h e n x i a n g h e n i z u o h a o p e n g y o u';
$arr = explode(" ",$str);
$a=array();
$b=array();
foreach ($arr as $key => $value){
    echo $value.'=>';
    echo $key.'</br>';
    //$b += $value;
}
//print_r($a);
//var_dump($b);
exit;
/*$a=array(1,2,34,76);
$b=array(
  'song'=>array('song','宋'),
   'zhi'=>array('zhi','志'),
    'lai'=>array('lai','来')
);
$a[0]=456;
print_r($b);
echo $b['song'][1];
var_dump($a);
$arr=array(10,2,3,4,5,6,7,9);
$a='';
for($i=0; $i<count($arr); $i++){
  $a +=$arr[$i];  
}
var_dump($a);*/



//冒泡排序法
/*$arr=array(23,1221,23,4435,67,798,-567,-3445,21212,-342,-121);
for($i=0; $i< count($arr)-1; $i++){
    for($j=0; $j<count($arr)-1-$i; $j++){
        if($arr[$j]>$arr[$j+1]){
            $b=$arr[$j];
            $arr[$j]=$arr[$j+1];
            $arr[$j+1]=$b;
        }
    }
}
var_dump($arr);
exit;*/



//二分法必须是有序数组
$arr=array(123,124,345,657,456456,1234122,123123123123,2212312313122);
 Erfenfa($arr,2212312313122,0,count($arr)-1);
 exit;

function Erfenfa($arr,$findVal,$leftIndex,$rightIndex){
    if($leftIndex>$rightIndex){
        echo '找不到!';
        return;
    }
   //找到中间的值
    $zhongJian=  ceil(($leftIndex+$rightIndex)/2);
    $zhongJianval=$arr[$zhongJian];
    if($findVal>$zhongJianval){
        Erfenfa($arr,$findVal,$zhongJian+1,$rightIndex);
    }else if($findVal<$zhongJianval){
        Erfenfa($arr,$findVal,$leftIndex,$zhongJian-1);
    }else{
        echo '找到了'.$zhongJianval.'下标为'.$zhongJian;
    }
}
?>
<script>
    var a=[10,12,5.7,9,14];
    var b= '';
    window.alert(a.length);
    for(var i=0 ; i<a.length ; i++){
         b +=a[i];
    };
    window.alert(b);
//window.alert(a[1]);
//window.alert('nihao ');
//document.write('宋志来');
</script>